{% extends 'base.html' %}

{% block title %}{{ grade.name }} 年级管理 - 班级管理系统{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
    <h2>{{ grade.name }} 年级管理仪表盘</h2>
    <span class="text-muted">{% now "Y年m月d日 l" %}</span>
</div>

    {% if grade %}
    <!-- 统计卡片 -->
    <div class="row mb-4">
        <div class="col-md-3 mb-4">
            <div class="card bg-primary text-white h-100">
                <div class="card-body">
                    <h5 class="card-title">班级数量</h5>
                    <p class="card-text display-4">{{ class_count }}</p>
                </div>
            </div>
        </div>
        <div class="col-md-3 mb-4">
            <div class="card bg-success text-white h-100">
                <div class="card-body">
                    <h5 class="card-title">学生总数</h5>
                    <p class="card-text display-4">{{ student_count }}</p>
                </div>
            </div>
        </div>
        <div class="col-md-3 mb-4">
            <div class="card bg-warning text-dark h-100">
                <div class="card-body">
                    <h5 class="card-title">纪律记录</h5>
                    <p class="card-text display-4">{{ discipline_count }}</p>
                </div>
            </div>
        </div>
        <div class="col-md-3 mb-4">
            <div class="card bg-info text-white h-100">
                <div class="card-body">
                    <h5 class="card-title">荣誉记录</h5>
                    <p class="card-text display-4">{{ honor_count }}</p>
                </div>
            </div>
        </div>
    </div>

    <!-- 评价统计 -->
    <div class="card mb-4">
        <div class="card-header">
            <h5>课程评价统计</h5>
        </div>
        <div class="card-body">
            <div class="row">
                <div class="col-md-4">
                    <div class="mb-3">
                        <div class="d-flex justify-content-between mb-1">
                            <span>好</span>
                            <span>{{ evaluation_stats.good|default:0 }}</span>
                        </div>
                        <div class="progress">
                            {% with total=evaluation_stats.good|default:0|add:evaluation_stats.medium|default:0|add:evaluation_stats.poor|default:0 %}
                            {% if total > 0 %}
                            <div class="progress-bar bg-success" style="width: {% widthratio evaluation_stats.good|default:0 1 total %}%"></div>
                            {% else %}
                            <div class="progress-bar bg-success" style="width: 0%"></div>
                            {% endif %}
                            {% endwith %}
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="mb-3">
                        <div class="d-flex justify-content-between mb-1">
                            <span>中</span>
                            <span>{{ evaluation_stats.medium|default:0 }}</span>
                        </div>
                        <div class="progress">
                            {% with total=evaluation_stats.good|default:0|add:evaluation_stats.medium|default:0|add:evaluation_stats.poor|default:0 %}
                            {% if total > 0 %}
                            <div class="progress-bar bg-warning" style="width: {% widthratio evaluation_stats.medium|default:0 1 total %}%"></div>
                            {% else %}
                            <div class="progress-bar bg-warning" style="width: 0%"></div>
                            {% endif %}
                            {% endwith %}
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="mb-3">
                        <div class="d-flex justify-content-between mb-1">
                            <span>差</span>
                            <span>{{ evaluation_stats.poor|default:0 }}</span>
                        </div>
                        <div class="progress">
                            {% with total=evaluation_stats.good|default:0|add:evaluation_stats.medium|default:0|add:evaluation_stats.poor|default:0 %}
                            {% if total > 0 %}
                            <div class="progress-bar bg-danger" style="width: {% widthratio evaluation_stats.poor|default:0 1 total %}%"></div>
                            {% else %}
                            <div class="progress-bar bg-danger" style="width: 0%"></div>
                            {% endif %}
                            {% endwith %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {% endif %}

    {% if classes %} 
    <div class="card shadow-sm">
        <div class="card-header bg-light">
            <h5 class="mb-0">本年级班级列表</h5>
        </div>
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead class="table-light">
                    <tr>
                        <th>班级名称</th>
                        <th>学期</th>
                        <th>班主任</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for class in classes %}
                    <tr>
                        <td>{{ class.grade.name }}{{ class.name }}</td>
                        <td>{{ class.semester }}</td>
                        <td>{{ class.homeroom_teacher.get_full_name|default:class.homeroom_teacher.username }}</td>
                        <td>
                            <div class="btn-group btn-group-sm">
                                <a href="{% url 'core:day_manage' class.id %}" class="btn btn-outline-primary"><i class="bi bi-eye me-2"></i>查看详情</a>
                                <a href="{% url 'core:class_evaluation_list' class.id %}" class="btn btn-outline-info"><i class="bi bi-list-check me-2"></i>评价记录</a>
                                <a href="{% url 'core:class_homework_stats' class.id '2024-01-01' %}" class="btn btn-outline-success"><i class="bi bi-book me-2"></i>作业管理</a>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
    {% else %}
    <div class="alert alert-info">
        暂无班级数据或您没有权限查看本年级班级
    </div>
    {% endif %}
</div>
{% endblock %}